﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：IActiveUnitOfWork.cs
// 功能描述：TongTongMall
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TongTongMall.Domain.Uow
{
    public interface IActiveUnitOfWork
    {
        /// <summary>
        /// 成功完成事件
        /// </summary>
        event EventHandler Completed;

        /// <summary>
        /// 异常事件
        /// </summary>
        event EventHandler<UnitOfWorkFailedEventArgs> Failed;

        /// <summary>
        /// 资源释放事件
        /// </summary>
        event EventHandler Disposed;

        /// <summary>
        /// 获取工作单元的配置参数
        /// </summary>
        UnitOfWorkOptions Options { get; }

        /// <summary>
        /// 获取工作单元内的过滤器
        /// </summary>
        IReadOnlyList<DataFilterConfiguration> Filters { get; }

        /// <summary>
        ///判断工作单元是否已经释放
        /// </summary>
        bool IsDisposed { get; }

        /// <summary>
        /// 保存
        /// </summary>
        void SaveChanges();

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        Task SaveChangesAsync();

        /// <summary>
        /// 禁用过滤器
        /// </summary>
        /// <param name="filterNames"></param>
        /// <returns></returns>
        IDisposable DisableFilter(params string[] filterNames);

        /// <summary>
        /// 启用过滤器
        /// </summary>
        /// <param name="filterNames"></param>
        /// <returns></returns>
        IDisposable EnableFilter(params string[] filterNames);

        /// <summary>
        /// 是否某个过滤器启用
        /// </summary>
        /// <param name="filterName"></param>
        /// <returns></returns>
        bool IsFilterEnabled(string filterName);

        /// <summary>
        /// 设置某个过滤器的参数
        /// </summary>
        /// <param name="filterName"></param>
        /// <param name="parameterName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        IDisposable SetFilterParameter(string filterName, string parameterName, object value);

        /// <summary>
        ///获取工作单元内的租户Id
        /// </summary>
        /// <returns></returns>
        long? GetTenantID();
    }
}
